#ifndef ALBUMWIDGET_H
#define ALBUMWIDGET_H

#include <QVector>
#include <QWidget>
#include <QListWidget>
#include <QScrollArea>
#include <QPainter>
#include <QPaintEvent>
#include <QVBoxLayout>
#include <QJsonObject>
#include <QJsonArray>

#include <albumtopwidget.h>
#include <songitem.h>
#include <popuplistwidget.h>
#include <bulkoperationwidget.h>
#include <QFile>

class  AlbumWidget : public QScrollArea
{
    Q_OBJECT
public:
    explicit AlbumWidget(QWidget *parent = nullptr);
    void AddSongItem(const QVector<SongItem*>&addsongitems);
    void DeleteSongItem(SongItem*delsongitems);
    void SetAlbumId(qint64 id){albumid=id;}
    void SetAlbumInfo(qint64 playcount,const QString&albumtitle,const QString&intro){albumtopw->SetAlbumInfo(playcount,albumtitle,intro);}
    void SetAlbumCreatorInfo(const QByteArray&picturedata,const QString&creatorname,const QStringList&tags,const QDate& date)
    {albumtopw->SetCreator(picturedata,creatorname,tags,date);}
    void SetAlbumCreatorInfo(const QString&filepath,const QString&creatorname,const QStringList&tags,const QDate& date)
    {albumtopw->SetCreator(filepath,creatorname,tags,date);}
    void SetAlbumCreatorId(qint64 id){albumcreatorid=id;}
    void SetSongItemCheck(bool flag);
    void SetAlbumPicture(const QPixmap&picture){albumtopw->SetAlbumPicture(picture);}
    void SetAlbumPicture(const QImage&picture){albumtopw->SetAlbumPicture(picture);}
    void SetMyLike(bool flag);
    void clean();
    bool Ready(){return ready;}
    qint64 AlbumId(){return albumid;}

signals:
    void getSongInfo(const QString&url);
    void playSignal(const QUrl&url);
    void likeSignal(qint64 songid);
    void normalSignal(qint64 songid);
    void addToNextSignal(qint64 songid);
    void favorSongSignal(qint64 songid);
    void deleteSongSignal(qint64 albumid,qint64 songid);
    void favorAlbumSignal(qint64 albumid);
    void shareAlbum(qint64 albumid);
    void playAllSignal(const QVector<SongItem*>&songitems);
    void downloadSignal(const QVector<SongItem*>&songitems);
    void favorSignal(const QVector<SongItem*>&songitems);
    void deleteSignal(const QVector<SongItem*>&songitems);
    void flush();
public slots:
    void onMainWindowResize(const QSize& size);
    void onMouseRightPress(const QPoint& mousepos);
    void onHttpsAlubmInfo(const QJsonObject&obj);
    void onSongInfoReady(const QJsonObject&obj);
    void onNextSong();
    void onPreviousSong();
    void onMetaDataReady();
    void onAlbumid(qint64 id){SetAlbumId(id);}
private slots:
    void onChosen();
    void onDoubleClicked();
    void onClickLike();
    void onClickNormal();
    void onPlayAll();
    void onFavor();
    void onDownload();
    void onMore(const QPoint&point);
    void onRightListWidgetItemClicked(QListWidgetItem*item);
    void onMoreListWidgetItemClicked(QListWidgetItem*item);
    void onClickBulkOperationPlayList();
    void onClickBulkOperationDownload();
    void onClickBulkOperationFavor();
    void onClickBulkOperationDelete();
    void onClickBulkOperationOK();
    void onSelectAll(bool flag);
    void onTextEdited(const QString&text);
protected:

    QVector<SongItem*>FindCheckedItem();
    void BulkOperationOver();

    AlbumTopWidget*albumtopw;
    BulkOperationWidget*bulkoperationw;
    QVBoxLayout*mainlayout;
    SongItemFirst* songitemfirst;
    QHBoxLayout*firstlayout;
    QVector<QHBoxLayout*>hlayouts;
    QVector<SongItem*>songitems;
    qint32 count=0;

    bool ready=false;
    QWidget*w;
    PopupListWidget*listw;
    PopupListWidget*morew;
    SongItem*lastclickitem;
    SongItem*lastplayitem;
    SongItem*lastrightclickitem;
    qint64 albumid=0;
    qint64 albumcreatorid;
};


#endif // ALBUMWIDGET_H
